function CertRateItem(item) {
  this.item = item;
  this.certRate = (item["certRate"]||"").trim();
  this.rankNameCn = (item["rankNameCn"]||"").trim();
  this.rankNameEn = (item["rankNameEn"]||"").trim();
  this.rateType="num";
  let reg = /^(\d+(\.\d+)?)%$/g;
  let getNumFull = (num)=>num;
  let getNumRate = (num)=>{

    let find = (/^(\d+(\.\d+)?)%$/g.exec(this.certRate));
    if (!find || find.length < 1){
      debugger;
    }
    let rate = find[1];
    let n= Math.ceil(num * parseFloat(rate) *0.01);
    return n > 1 ? n : 1;
  };
  let getNumSetting = (num)=>{
    let n= Math.ceil(parseFloat(this.certRate));
    return n > 1 ? n : 1;
  };
  this.getCertNum = getNumSetting;
  if (this.certRate == "*"){
    this.rateType= "*";
    this.getCertNum = getNumFull;
  }else if (reg.test(this.certRate)){
    this.rateType= "rate";
    this.getCertNum = getNumRate;
  }
}

function DetailSetting(type) {
  this.certRateMap = {};

  let init = () => {
    let setting = _Setting.loadDetailSetting(type);
    this.certRateMap = {};

    (setting || []).forEach(item => {
      let key = getKey(item);
      let detailItem = this.certRateMap[key];
      if (!detailItem) {
        detailItem = {"default": null, "others": []};
        this.certRateMap[key] = detailItem;
      }
      let itemName = "*";
      if (item["key"]) {
        detailItem.others.push(item)
      } else {
        detailItem["default"] = item;
      }
      item["certRateArray"] = (item["certRateArray"] || []).map(t => new CertRateItem(t))
    })
  };
  let getKey = (item) => item["certType"] + "." + item["area"];
  this.getDetailItem = function (options = {}, pool = {}) {
    let key = getKey(options);
    let detailItem = this.certRateMap[key];
    if (!detailItem) {
      console.error("未找到相应的评奖信息,key:", key)
      return null;
    }

    for (let i = 0; i < detailItem.others.length; i++) {
      let temp = detailItem.others[i];
      if (pool[temp.key] && pool[temp.key] == temp.value) {
        return temp;
      }
    }
    if (!detailItem.default) {
      console.error("未找到相应的评奖的设置,key:", key);
    }
    return detailItem.default;
  }
  init();

}
